Hello! I've looked at @eskimo's sample code, and have ended in a situation. NetService has been deprecated, and I'm looking into what can be done in its stead? I'm currently running a temporary connection with NWConnection but even here I fail to find the host, so I can make a HTTP connection.
Post
Replies
Boosts
Views
Activity
Which package are you trying to add, and how?
Has anyone written a feedback for this? It seems like a common issue.
I fixed the issue.
I called defer { url.stopAccessingSecurityScopedResource() } before I actually made the bookmark, maybe a bug in iOS 13 let this through?
Thanks for your help!
I got my entire codebase on GitHub, I get the files from the users @Environment(\.importFiles).
file(multipleOfType: [.audio]) { result in
switch result {
case .success(let urls):
openSong (urls: urls)
break
case .failure(let error):
print(error)
break
case .none:
print("No item was selected")
}
}
GitHub - https://github.com/Human-Entertainment/Listen-in-Place/blob/0e6521ea0036236192552cab6c896d620f3fb9d6/Shared/ContentView.swift#L35-L46
Because of the weird issue I got from the bookmark thing, I've refactored it so I don't get the URL from the bookmark immediately after. But there's still issues reading the file it seems, which I'm debugging further. (This doesn't return Future<Song, SongError>{ $0(.failure(.coundtReadFile)) } weirdly enough
func load(url: URL, bookmark: Data) throws -> Future<Song, SongError> {
var loaded: (URL?, Error?) = (nil, nil)
let coordinator = NSFileCoordinator()
url.coordinatedRead(coordinator) { inputURL,inputError	in
loaded = (inputURL, inputError)
}
guard let loadURL = loaded.0 else { return Future<Song, SongError>{ $0(.failure(.coundtReadFile)) } }
return Future<Song, SongError> { promise in
self.threadPool.start()
let loaded = self.asyncLoad(url: loadURL, bookmark: bookmark)
loaded.whenSuccess { song in
promise(.success(song))
}
loaded.whenFailure { error in
print(error)
promise(.failure(.coundtReadFile))
}
}
}
GitHub - https://github.com/Human-Entertainment/Listen-in-Place/blob/0e6521ea0036236192552cab6c896d620f3fb9d6/Shared/SongReader/Song.swift#L57-L81
This function could also be important if you're curious how I get the bookmark.
func add(url: URL) {
container.performBackgroundTask { [self] context in
do {
let newSong = Songs(context: context)
let bookmark = try url.bookmarkData()
newSong.bookmark = bookmark
fetchSong(url: url, bookmark: bookmark)
} catch {
print("An error occured: \(error)")
}
try? context.save()
}
}
GitHub - https://github.com/Human-Entertainment/Listen-in-Place/blob/0e6521ea0036236192552cab6c896d620f3fb9d6/Shared/SongReader/Player.swift#L25-L42
I see you use the document in the apps sandboxing, which I don't do, so I assume that I did something wrong in requesting access for files outside my apps sandboxing?
Cheers, Bastian Inuk Christensen
@BabyJ I tried your solution, but I can't seem to get the bookmark, do you know what's cracking?
edit: The issue seems to be me, the file doesn't exist anymore, according to this error:
Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist."